#include <netcm.h>

int main()
{
    char *host_list="ftp://user1:pass1@www.xxx.com:100 | "
        "http://user2@www.yyy.com:110 | www.zzz.com , backup.com";
    struct host_addr_info *ready;
    int ready_num;
    struct host_addr_info *backup;
    char *host="https://user:pass@www.xxx.org:1000";
    struct host_addr_info host_info;
    int res;
    int i;

    if((res=host_list_parse(host_list, &ready, &ready_num, &backup)))
    {
        printf("host_list_parse fail, res:%d\n", res);
        return(-1);
    }
    printf("host_list: %s\n", host_list);
    printf("ready:\n");
    for(i=0; i<ready_num; i++)
    {
        printf("    %d:\n", i+1);
        printf("        protocol: %s\n", ready[i].protocol);
        printf("        user:     %s\n", ready[i].user);
        printf("        passwd:   %s\n", ready[i].passwd);
        printf("        host:     %s\n", ready[i].host);
        printf("        port:     %d\n", ready[i].port);
    }
    printf("backup:\n");
    printf("    protocol: %s\n", backup->protocol);
    printf("    user:     %s\n", backup->user);
    printf("    passwd:   %s\n", backup->passwd);
    printf("    host:     %s\n", backup->host);
    printf("    port:     %d\n", backup->port);
    printf("\n");

    host="https://user:pass@www.xxx.org:1000";
    if((res=host_addr_parse(host, &host_info)))
    {
        printf("host_addr_parse fail, res:%d\n", res);
        return(-1);
    }
    printf("host: %s\n", host);
    printf("    protocol: %s\n", host_info.protocol);
    printf("    user:     %s\n", host_info.user);
    printf("    passwd:   %s\n", host_info.passwd);
    printf("    host:     %s\n", host_info.host);
    printf("    port:     %d\n", host_info.port);
    printf("\n");

    host="http://user:@www.xxx.org";
    if((res=host_addr_parse(host, &host_info)))
    {
        printf("host_addr_parse fail, res:%d\n", res);
        return(-1);
    }
    printf("host: %s\n", host);
    printf("    protocol: %s\n", host_info.protocol);
    printf("    user:     %s\n", host_info.user);
    printf("    passwd:   %s\n", host_info.passwd);
    printf("    host:     %s\n", host_info.host);
    printf("    port:     %d\n", host_info.port);
    printf("\n");

    host=":@www.xxx.org:";
    if((res=host_addr_parse(host, &host_info)))
    {
        printf("host_addr_parse fail, res:%d\n", res);
        return(-1);
    }
    printf("host: %s\n", host);
    printf("    protocol: %s\n", host_info.protocol);
    printf("    user:     %s\n", host_info.user);
    printf("    passwd:   %s\n", host_info.passwd);
    printf("    host:     %s\n", host_info.host);
    printf("    port:     %d\n", host_info.port);
    printf("\n");

    host="@www.xxx.org";
    if((res=host_addr_parse(host, &host_info)))
    {
        printf("host_addr_parse fail, res:%d\n", res);
        return(-1);
    }
    printf("host: %s\n", host);
    printf("    protocol: %s\n", host_info.protocol);
    printf("    user:     %s\n", host_info.user);
    printf("    passwd:   %s\n", host_info.passwd);
    printf("    host:     %s\n", host_info.host);
    printf("    port:     %d\n", host_info.port);
    printf("\n");

    host="www.xxx.org:80";
    if((res=host_addr_parse(host, &host_info)))
    {
        printf("host_addr_parse fail, res:%d\n", res);
        return(-1);
    }
    printf("host: %s\n", host);
    printf("    protocol: %s\n", host_info.protocol);
    printf("    user:     %s\n", host_info.user);
    printf("    passwd:   %s\n", host_info.passwd);
    printf("    host:     %s\n", host_info.host);
    printf("    port:     %d\n", host_info.port);
    printf("\n");

    return(0);
}
